//
//  KWLFeedbackFunctionViewController.m
//  KWNLaywerClient
//
//  Created by 孔六五 on 15/2/2.
//  Copyright (c) 2015年 张明磊. All rights reserved.
//

#import "KWLFeedbackFunctionViewController.h"
#import "RESideMenu.h"
#import "KFLFeedbackRequest.h"

@interface KWLFeedbackFunctionViewController ()<UITextViewDelegate>
@property (nonatomic,strong) UITextView *textview_feedback;
@property (nonatomic,strong) UILabel *label_remind;
@end

@implementation KWLFeedbackFunctionViewController
@synthesize textview_feedback;
@synthesize label_remind;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    
    [self ui_title:@"用户反馈" withLeftImageName:@"btn_leftList.png" withReftImageName:@"提交"];
    [self.button_left addTarget:self action:@selector(feedbackFunctionLeftBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.button_right addTarget:self action:@selector(feedbackFunctionRightBtnClick:) forControlEvents:UIControlEventTouchUpInside];

    label_remind = [[UILabel alloc] initWithFrame:CGRectMake(8, 5, 100, 15)];
    label_remind.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
    label_remind.textColor = RGB(211, 211, 211);
    label_remind.backgroundColor = [UIColor clearColor];
    label_remind.text = @"请写下您的意见";

    textview_feedback = [[UITextView alloc] initWithFrame:CGRectMake(10, self.view_title_super.frame.origin.y + self.view_title_super.frame.size.height + 10, MainScreenWidth - 20, MainScreenHeight - self.view_title_super.frame.origin.y - self.view_title_super.frame.size.height - 10 - Iphone5_size(250, 210))];
    textview_feedback.backgroundColor = [UIColor clearColor];
//    textview_feedback.text = @"请写下您的意见";
//    textview_feedback.textColor = RGB(211, 211, 211);
    textview_feedback.textColor = RGB(109, 109, 109);
    textview_feedback.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
    textview_feedback.autocorrectionType = UITextAutocorrectionTypeNo;
    textview_feedback.autocapitalizationType = UITextAutocapitalizationTypeNone;
    [self.view addSubview:textview_feedback];
    textview_feedback.delegate = self;
    textview_feedback.tag = 200;
    textview_feedback.layer.borderColor = RGB(190, 190, 190).CGColor;
    textview_feedback.layer.borderWidth = 1;
    textview_feedback.layer.cornerRadius = 4;
    textview_feedback.returnKeyType = UIReturnKeyDone;
    
    [textview_feedback addSubview:label_remind];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)feedbackFunctionLeftBtnClick:(id)sender
{
    [[RESideMenu sharedInstance] presentMenuViewController];
    [MobClick event:@"caidan"];
}

- (void)feedbackFunctionRightBtnClick:(id)sender
{
    if (textview_feedback.text.length<=0 || !textview_feedback.text) {
        [SVProgressHUD showErrorWithStatus:@"信息不能为空" duration:1.5];
    }
    else
    {
        [SVProgressHUD showWithStatus:@"提交中..."];
        KFLFeedbackRequest *request = [[KFLFeedbackRequest alloc] initRequest];
        request.string_feedback = textview_feedback.text;
        [request startToRequestWithBlock:^(NSInteger stateCode, NSMutableArray *result) {
            switch (stateCode) {
                case 10000:
                {
                    [SVProgressHUD showSuccessWithStatus:@"提交成功" duration:2];
                    [textview_feedback resignFirstResponder];
                    textview_feedback.text = @"";
                    label_remind.hidden = NO;
                    textview_feedback.tag = 200;

                }
                    break;
                default:
                {
                    NSString *msg = [result objectAtIndex:0];
                    [SVProgressHUD showErrorWithStatus:msg duration:1.5];
                }
                    break;
            }
        }];
    }

}
#pragma mark - UITextViewDelegate -
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;
{
    if (label_remind.hidden != YES) {
        label_remind.hidden = YES;
    }
    return YES;
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if(text && textView.tag == 200){
        textView.textColor = RGB(109, 109, 109);
        textView.text = @"";
        textView.tag = 201;
    }

    if ([text isEqualToString:@"\n"])
    {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
